package com.hongye.app.model;

import java.util.List;

import com.hongye.util.Utils;
import com.jfinal.plugin.activerecord.Model;

public class ContentModel extends Model<ContentModel>{
	private static final long serialVersionUID = 1L;
	public static final ContentModel dao = new ContentModel();
	
	/**
	 * 获取全部list
	 * @author lifuqiang
	 * 2017-3-29
	 * @return
	 */
	public static List<ContentModel> getContentList(){
		String sql = "SELECT * FROM content ORDER BY c_time DESC";
		List<ContentModel> list = dao.find(sql);
		return list;
	}
	
	/**
	 * 添加新ContentModel
	 * @author lifuqiang
	 * 2017-3-29
	 * @param type
	 * @param title
	 * @param content
	 * @param summary
	 * @param status
	 * @return
	 */
	public static boolean addNewContent(String type, String title, String content, String summary, String status){
		ContentModel cm = new ContentModel();
		return cm.set("type", type).set("title", title).set("content", content).set("summary", summary).set("status", status).set("c_time", Utils.getDate()).save();
	}
	
	/**
	 * 修改ContentModel
	 * @author lifuqiang
	 * 2017-3-29
	 * @param type
	 * @param title
	 * @param content
	 * @param summary
	 * @param status
	 * @return
	 */
	public static boolean updateContent(String id, String title, String content, String summary, String status){
		ContentModel contentModel = dao.findById(id);
		return contentModel.set("title", title).set("content", content).set("summary", summary).set("status", status).set("u_time", Utils.getDate()).update();
	}
	
	/**
	 * 根据ID删除ContentModel
	 * @author lifuqiang
	 * 2017-3-29
	 * @param id
	 * @return
	 */
	public static boolean deleteConten(String id){
		return dao.deleteById(id);
	}
	
	/**
	 * 根据ID获取ContentModel
	 * @author lifuqiang
	 * 2017-3-29
	 * @param id
	 * @return
	 */
	public static ContentModel getContentModel(String id){
		return dao.findById(id);
	}
}
